package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusSalesSlip;
import com.drug.wms.page.BusSalesSlipPage;
import com.drug.wms.service.IBusSalesSlipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品销售单Controller
 *
 * @author ruoyi
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/wms/salesSlip")
public class BusSalesSlipController extends BaseController {
    @Autowired
    private IBusSalesSlipService busSalesSlipService;

    /**
     * 查询商品销售单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:slip:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusSalesSlip busSalesSlip) {
        startPage();
        List<BusSalesSlip> list = busSalesSlipService.selectBusSalesSlipList(busSalesSlip);
        return getDataTable(list);
    }

    /**
     * 导出商品销售单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:slip:export')")
    @Log(title = "商品销售单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusSalesSlip busSalesSlip) {
        List<BusSalesSlip> list = busSalesSlipService.selectBusSalesSlipList(busSalesSlip);
        ExcelUtil<BusSalesSlip> util = new ExcelUtil<BusSalesSlip>(BusSalesSlip.class);
        return util.exportExcel(list, "商品销售单数据");
    }

    /**
     * 获取商品销售单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:slip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busSalesSlipService.selectBusSalesSlipById(id));
    }

    /**
     * 新增商品销售单
     */
//    @PreAuthorize("@ss.hasPermi('system:slip:add')")
    @Log(title = "商品销售单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusSalesSlipPage busSalesSlipPage) {
        return toAjax(busSalesSlipService.insertBusSalesSlip(busSalesSlipPage));
    }

    /**
     * 修改商品销售单
     */
//    @PreAuthorize("@ss.hasPermi('system:slip:edit')")
    @Log(title = "商品销售单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusSalesSlipPage busSalesSlipPage) {
        return toAjax(busSalesSlipService.updateBusSalesSlip(busSalesSlipPage));
    }

    /**
     * 删除商品销售单
     */
//    @PreAuthorize("@ss.hasPermi('system:slip:remove')")
    @Log(title = "商品销售单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busSalesSlipService.deleteBusSalesSlipByIds(ids));
    }
}
